/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package myftp.app.action;

import myftp.app.model.ServerManagerModel;
import myftp.app.model.ServerModel.TransferState;
import myftp.app.model.ServerTransferModel;
import myftp.app.model.TransfertTableModel;
import myftp.app.view.dialog.TemplateDialog;
import myftp.core.action.AbstractAction;

/**
 *
 * @author CAVARLE Glenn, LUCAS Stéphane
 * Annule un tranfert
 */
public class StopAction extends AbstractAction {

    public void run() {

        /* Récupération des paramètres */
        int aTransfert = (Integer) this.getParam("number");
        TransfertTableModel aTransfertsTable = (TransfertTableModel) this.getParam("table");

        ServerManagerModel manager = (ServerManagerModel) this.getModel();

        /* Demande la confirmation de l'annulation du transfert */
        Integer response = TemplateDialog.showStopDialog();
        if (response == TemplateDialog.YES_OPTION) {

            /* Arret du transfert */
            ServerTransferModel transfer = manager.getTransferAction(aTransfert);
            transfer.getTransferServer().stopTransfer(TransferState.ST_STOP);
            System.out.println("Téléchargement N°" + aTransfert + "ANNULE");

        }
    }

    public boolean init() {
        /* Validation de l'initialisation, lancement du thread */
        return true;
    }
}
